package com.sxm.yiwei.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.sxm.yiwei.R;
import com.sxm.yiwei.activitis.MsgFollowActivity;
import com.sxm.yiwei.beans.Collect;
import com.sxm.yiwei.tools.CircleTransform;
import com.sxm.yiwei.utils.InternetAddressUtis;

import org.xutils.x;

import java.util.List;

/**
 * Created by KuKa on 2017/7/28.
 * 收藏列表
 */

public class CollectAdapter extends BaseAdapter {
    Context context;
    public List<Collect.DataBean> list;
    public CollectAdapter(Context context, List<Collect.DataBean> list) {
        this.context=context;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        View view;
        ViewHolder holder;
        if (convertView==null){
            view = View.inflate(context, R.layout.collect_item,null);
            holder = new ViewHolder();
            holder.bao = (ImageView) view.findViewById(R.id.collect_bao);
            holder.grade = (ImageView) view.findViewById(R.id.collect_grade);
            holder.img = (ImageView) view.findViewById(R.id.collect_itemimg);
            holder.type = (ImageView) view.findViewById(R.id.collect_type);
            holder.sell = (ImageView) view.findViewById(R.id.collect_sell);
            holder.name = (TextView) view.findViewById(R.id.collect_itemname);
            holder.explain = (TextView) view.findViewById(R.id.collect_explain);
            holder.distance = (TextView) view.findViewById(R.id.collect_distance);
            holder.xinnum = (TextView) view.findViewById(R.id.collect_xinnum);
            holder.delete = (TextView) view.findViewById(R.id.collect_itemdelete);
            view.setTag(holder);
        }else {
            view = convertView;
            holder = (ViewHolder) view.getTag();
        }
        holder.name.setText(list.get(position).getName());
        holder.explain.setText(list.get(position).getIntro());
        holder.distance.setText(list.get(position).getDistance()+"");
        Picasso.with(context).load(InternetAddressUtis.IMG_URL+ list.get(position).getAvatar()).error(R.mipmap.morentouxiang).transform(new CircleTransform()).into(holder.img);


        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickDelete!=null){
                    onClickDelete.OnDelete(position);
                }
            }
        });

        notifyDataSetChanged();
        return view;
    }

    class ViewHolder{
        TextView name,distance,xinnum,explain,delete;
        ImageView img,bao,sell,grade,type;
    }
    public interface  OnClickDelete{
        void OnDelete(int p);
    }
    OnClickDelete onClickDelete;
    public void setOnClickDelete(OnClickDelete onClickDelete){
        this.onClickDelete=onClickDelete;
    }
}
